package erfgame.core.graphics.renderer;


import erfgame.core.dao.ObjectDAO;
import erfgame.core.entity.Entity;
import erfgame.core.world.World;

public class CachingOrientableEntityRendererDelegateFactory extends
		OrientableEntityRendererDelegateFactory {
	private ObjectDAO<Entity, EntityRenderer[]> cache;
	
	public CachingOrientableEntityRendererDelegateFactory(EntityRendererFactory[] rendererFactories, ObjectDAO<Entity, EntityRenderer[]> cache) {
		super(rendererFactories);
		this.cache = cache;
	}
	@Override
	protected EntityRenderer[] getRenderers(World world,
			erfgame.core.entity.Entity entity) {
		if( cache.containsObject(entity) ) {
			return cache.retrieveObject(entity);
		} else {
			EntityRenderer[] renderers = super.getRenderers(world, entity);
			this.cache.storeObject(entity, renderers);
			return renderers;
		}
	}
}
